# -*- coding: utf-8 -*-
import unittest
from graphs.matrixgraph import MatrixGraph


class MatrixGraphTest(unittest.TestCase):

    def setUp(self):
        self.graph = MatrixGraph()

    def test_add_two_vertices(self):
        self.graph.add_vertex('V1')
        self.graph.add_vertex('V2')

        self.assertEqual(2, self.graph.vertex_count())

    def test_add_fifteen_vertices(self):
        n = 15
        for i in range(n):
            name = 'V' + str(i)
            self.graph.add_vertex(name)

        self.assertEqual(n, self.graph.vertex_count())

    def test_add_vertices_add_edge_check_edge(self):
        n = 15
        for i in range(n):
            name = 'V' + str(i)
            self.graph.add_vertex(name)

        self.graph.add_edge('V4', 'V5', 1)

        weight = self.graph.get_edge('V4', 'V5')

        self.assertEqual(1, weight)

    def test_load(self):
        self.graph.load('inputs/test1.txt')

        self.assertEqual(6, self.graph.vertex_count())

        self.assertEqual(1, self.graph.get_edge('s', 'u'))
        self.assertEqual(2, self.graph.get_edge('s', 'v'))
        self.assertEqual(4, self.graph.get_edge('s', 'x'))

        self.assertEqual(1, self.graph.get_edge('u', 'x'))
        self.assertEqual(3, self.graph.get_edge('u', 'y'))

        self.assertEqual(2, self.graph.get_edge('v', 'x'))
        self.assertEqual(3, self.graph.get_edge('v', 'z'))

        self.assertEqual(1, self.graph.get_edge('x', 'y'))
        self.assertEqual(2, self.graph.get_edge('x', 'z'))
